//
// Created by Admin on 2021/9/22.
//
#include "my_queue.h"
pQueue make_queue(){
    return calloc(1,sizeof(Queue));
}

void enqueue(pQueue queue, pQueueItem item){
    if(queue->front==NULL){
        queue->front = item;
        queue->end = item;
    } else {
        queue->end->next = item;
        queue->end = item;
        item->next = NULL;
    }
}

pQueueItem front(pQueue queue){
    return queue->front;
}

int dequeue(pQueue queue){
    if(queue->front==NULL){
        queue->end = NULL;
        return 0;
    }else{
        pQueueItem tmp = queue->front;
        queue->front = queue->front->next;
        free(tmp);
        return 1;
    }
}

pQueueItem dequeue_k(pQueue queue){
    if(queue->front==NULL){
        queue->end = NULL;
        return 0;
    }else{
        pQueueItem tmp = queue->front;
        queue->front = queue->front->next;
        return tmp;
    }
}

void destroy_queue(pQueue queue){
    while(dequeue(queue));
    free(queue);
}

void print_queue(pQueue queue){
    pQueueItem tmp = queue->front;
    while(tmp){
        printf("%s <- ",tmp->value);
        tmp = tmp->next;
    }
    printf("\n");
}